package com.bang.study.jvm.oom;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import javax.crypto.Mac;
import java.lang.reflect.Method;

/**
 * @Auther: Bang
 * @Date: 2019/9/29 21:50
 * @Description:模拟java元空间溢出
 * @VM -Xms20m -Xmx20m -XX:MetaspaceSize=10m -XX:MaxMetaspaceSize=10m
 */
public class MetaspaceOOM {

    public static void main(String[] args) {
        while (true) {
            Enhancer enhancer = new Enhancer();
            enhancer.setSuperclass(OomObject.class);
            enhancer.setUseCache(false);
            enhancer.setCallback(new MethodInterceptor() {
                @Override
                public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
                    return methodProxy.invoke(o, objects);
                }
            });
            OomObject o = (OomObject) enhancer.create();
        }

    }


    static class OomObject {


    }
}
